<?php

class StudentFormStep2 extends Form
{
	const L_FIELD_REQUIRED = 'Dit veld is verplicht';

	public function __construct( $data = array() )
	{
		parent::__construct( );
		
		$schoolgegevens = new FieldSet( 'Studentgegevens' );
		
		$studentNo = new InputText( 'web_proj_7_stud_nr', Student::getField('web_proj_7_stud_nr'), isset( $data[ 'web_proj_7_stud_nr' ] ) ? $data[ 'web_proj_7_stud_nr' ] : '', 'studentno' );
		$studentNo->getValidator()->required( self::L_FIELD_REQUIRED );
		$schoolgegevens->addChild( $studentNo );
		
		$educationField = Student::getField('education');

		$edu = new SelectOneChoice( 'education', $educationField  );
		$edu->addValues( $educationField->getOptions() );
		$edu->setSelected( isset( $data[ 'education' ] ) ? $data[ 'education' ] : $educationField->getDefaultValue() );
		$schoolgegevens->addChild( $edu );
		
		$this->addChild( $schoolgegevens );
		
		$secondLocation = new FieldSet('Tweede verblijfplaats');
		$secondLocation->addChild( new PlainText( 'Onderstaande gegevens alleen invullen indien er een stage in het buitenland van toepassing is.' ) );
		
		$straat = new InputText( 'alt_address_street', Student::getField('alt_address_street'), isset( $data[ 'alt_address_street' ] ) ? $data[ 'alt_address_street' ] : '', 'street' );
		//$straat->getValidator()->required( self::L_FIELD_REQUIRED );
		$secondLocation->addChild( $straat );
		
		$postal = new InputText( 'alt_address_postalcode', Student::getField('alt_address_postalcode'), isset( $data[ 'alt_address_postalcode' ] ) ? $data[ 'alt_address_postalcode' ] : '', 'postal' );
		//$postal->getValidator()->required( self::L_FIELD_REQUIRED );
		$secondLocation->addChild( $postal );
		
		$city = new InputText( 'alt_address_city', Student::getField('alt_address_city'), isset( $data[ 'alt_address_city' ] ) ? $data[ 'alt_address_city' ] : '', 'city' );
		//$city->getValidator()->required( self::L_FIELD_REQUIRED );
		$secondLocation->addChild( $city );
		
		$country = new InputText( 'alt_address_country', Student::getField('alt_address_country'), isset( $data[ 'alt_address_country' ] ) ? $data[ 'alt_address_country' ] : '', 'street' );
		//$country->getValidator()->required( self::L_FIELD_REQUIRED );
		$secondLocation->addChild( $country );
		
		$this->addChild( $secondLocation );
		
		$this->addChild( new SubmitButton( 'previous', 'Stap terug' ) );
		$this->addChild( new SubmitButton( 'submit', 'Volgende stap' ) );
	}
	
	public function hasSecondaryAddress()
	{
		return ( $this->children['Tweede verblijfplaats']['alt_address_street']->getProperty('value') != '' );
	}
}
